package yuejian_07.yuejian_07.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.activity.ShowInfoActivity;
import yuejian_07.yuejian_07.javabean.Show;

/**
 * Created by dell on 2017/10/16.
 */

public class ShowListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ShowListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Show entity = (Show) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.s_content.setText(entity.getS_content());
        viewHolder.time.setText(entity.getS_date());
        viewHolder.user_name.setText(entity.getUser_name());
        String user_pic="http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getUser_pic();

        Picasso.with(mContext).load(user_pic).into(viewHolder.user_pic);
        if(viewHolder.user_pic.getDrawable()==null){
            viewHolder.user_pic.setImageResource(R.drawable.no_pic);
        }


      String s_pic ="http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getS_pic();

      Picasso.with(mContext).load(s_pic).into(viewHolder.s_pic);
        if(viewHolder.s_pic.getDrawable()==null){
            viewHolder.s_pic.setImageResource(R.drawable.no_pic);
        }
//        /viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("s_id",entity.getS_id());
                bundle.putInt("user_id",entity.getUser_id());
                bundle.putString("s_content",entity.getS_content());
                //bundle.putInt("s_address",entity.getTrain_price());
                bundle.putString("s_address",entity.getS_address());
                Intent intent=new Intent(mContext, ShowInfoActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
   }

       @Override
    public int getItemCount() {
        return mDataList.size();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_show, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView s_pic,user_pic;
        TextView s_content,time,user_name;

        public ViewHolder(View itemView) {
            super(itemView);

            s_pic = (ImageView) itemView.findViewById(R.id.Showlis1t_pic);
            user_pic = (ImageView) itemView.findViewById(R.id.user_pic);
            s_content=(TextView) itemView.findViewById(R.id.content1);
            user_name = (TextView) itemView.findViewById(R.id.user_name);
            time=(TextView)itemView.findViewById(R.id.time);

        }
    }
}
